home *** CD-ROM | disk | FTP | other *** search
/ InfoMagic Internet Tools 1993 July / Internet Tools.iso / RockRidge / security / xinetd / fsma.2.0.1 / fsma.h < prev    next >
Encoding:
C/C++ Source or Header  |  1992-11-08  |  2.0 KB  |  88 lines

  1. /*
  2.  * (c) Copyright 1992 by Panagiotis Tsirigotis
  3.  * All rights reserved.  The file named COPYRIGHT specifies the terms 
  4.  * and conditions for redistribution.
  5.  */
  6.  
  7. #ifndef __FSMA_H
  8. #define __FSMA_H
  9.  
  10. /*
  11.  * $Id: fsma.h,v 5.4 1992/10/20 21:20:34 panos Exp $
  12.  */
  13.  
  14. #define __FSMA_ALIGNMENT                    8
  15.  
  16. union __fsma_chunk_header
  17. {
  18.     union __fsma_chunk_header *next_chunk ;
  19.     char bytes[ __FSMA_ALIGNMENT ] ;
  20. } ;
  21.  
  22. typedef char *__fsma_pointer ;
  23.  
  24. struct __fsma_header
  25. {
  26.     union __fsma_chunk_header *chunk_chain ;
  27.     __fsma_pointer next_free ;
  28.     __fsma_pointer temp ;
  29.     unsigned slots_in_chunk ;
  30.     unsigned slot_size ;
  31.     unsigned chunk_size ;
  32.     int flags ;
  33.     int is_inlined ;                        /* header is inlined (boolean)    */
  34. } ;
  35.  
  36. typedef struct __fsma_header *fsma_h ;
  37.  
  38. /*
  39.  * Flags
  40.  */
  41. #define FSM_NOFLAGS                    0x0
  42. #define FSM_RETURN_ERROR            0x1
  43. #define FSM_ZERO_ALLOC                0x2
  44. #define FSM_ZERO_FREE                0x4
  45. #define FSM_ZERO_DESTROY            0x8
  46.  
  47.  
  48. /*
  49.  * INTERFACE
  50.  */
  51.  
  52. #ifdef __ARGS
  53. #undef __ARGS
  54. #endif
  55.  
  56. #ifdef PROTOTYPES
  57. #  define __ARGS( s )               s
  58. #else
  59. #  define __ARGS( s )               ()
  60. #endif
  61.  
  62. fsma_h fsm_create __ARGS( ( unsigned size, unsigned slots, int flags ) ) ;
  63. void fsm_destroy __ARGS( ( fsma_h handle ) ) ;
  64. char *_fsm_alloc __ARGS( ( fsma_h handle ) ) ;
  65. void _fsm_free __ARGS( ( fsma_h handle, char *ptr ) ) ;
  66.  
  67. #define fsm_alloc( fsma )                                                                \
  68.     (                                                                                            \
  69.         ( ! (fsma)->next_free || (fsma)->flags & FSM_ZERO_ALLOC )         \
  70.             ? _fsm_alloc( fsma )                                                            \
  71.             : ((fsma)->temp = (fsma)->next_free,                           \
  72.                 (fsma)->next_free = *(__fsma_pointer *) (fsma)->next_free,  \
  73.                 (char *) (fsma)->temp)                                                    \
  74.     )
  75.  
  76. #define fsm_free( fsma, p )                                                            \
  77.             if ( (fsma)->flags & FSM_ZERO_FREE )                                    \
  78.                 _fsm_free( fsma, p )    ;                                                    \
  79.             else                                                                                \
  80.                 (fsma)->temp = (p),                                                        \
  81.                 *(__fsma_pointer *) (fsma)->temp = (fsma)->next_free,         \
  82.                 (fsma)->next_free = (fsma)->temp
  83.  
  84. #define fsm_size( fsma )            (fsma)->slot_size
  85.  
  86. #endif     /* __FSMA_H */
  87.  
  88.